
#import "HUploadDataViewController.h"
#import "HSeeRecordViewController.h"
#import <TMCache.h>
#import "HNurseAssessRecordViewController.h"
@interface HUploadDataViewController ()
  
@property (nonatomic,strong)NSDictionary *DataSourceIcon;
@property (nonatomic,strong)NSArray *menuArray;
@end

@implementation HUploadDataViewController


- (void)viewDidLoad {
    [super viewDidLoad];
     
    [self.view addSubview:self.myTableView];
    self.menuArray  = [[TMCache sharedCache]objectForKey:@"menu"];
    NSLog(@"%@",self.menuArray);
    self.view.backgroundColor = RGB(0xf9, 0xf9, 0xf9);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


-(instancetype)init{
    
    self.theEmployee = UserDefault.getUserInfo;
    
    self.DataSource = [[NSDictionary alloc ]init];
    
    NSArray *arr1 = [[NSArray alloc]initWithObjects:@"质量检查", @"满意度调查",@"夜查房",@"操作过程考核", nil];
    
    NSArray *arr1_icon = [[NSArray alloc]initWithObjects:@"上传", @"上传",@"上传",@"上传", nil];
    
    self.DataSource = [[NSDictionary alloc]initWithObjectsAndKeys: arr1, @"A", nil ];
    
    self.DataSourceIcon = [[NSDictionary alloc]initWithObjectsAndKeys: arr1_icon, @"A", nil ];
    
    return self;
}



- (UITableView *)myTableView{
    if (!_myTableView ) {
        _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavBarHeight, ScreenWidth, ScreenHeight - 50)];
        _myTableView.dataSource = self;
        _myTableView.delegate = self;
        _myTableView.tableFooterView = [[UIView alloc]init];
    }
    return _myTableView;
}


-(NSArray*)GetArrBySection:(NSInteger) section{
    NSArray *array = self.DataSource[self.DataSource.allKeys[section]];
    return array;
}

#pragma mark UITableView 委托

//
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    return 40;
//}

//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
//    
//    if(section == self.DataSource.allKeys.count - 1){
//        return 30;
//    }
//    return 0;
//}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 30;
}


- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return  nil;
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.DataSource.allKeys.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *array = [self GetArrBySection:section];
    return array.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"cell";
    UITableViewCell *cell = [self.myTableView dequeueReusableCellWithIdentifier:cellID];
    
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
    }
    
    NSString *key = self.DataSource.allKeys[indexPath.section];
    NSArray *arr = self.DataSource[key];
    NSArray *arr_icon = self.DataSourceIcon[key];
    
    cell.textLabel.text = arr[indexPath.row];
    [cell.imageView setImage:[UIImage imageNamed:arr_icon[indexPath.row]]];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSArray *array = [self GetArrBySection:indexPath.section];
    
    NSString *title = array[indexPath.row];
    
    NSDictionary *DIC = @{};
    NSDictionary *manyidu = @{};
    NSDictionary *kaohe = @{};
    NSDictionary *yechafang = @{};
    for (NSMutableDictionary *dic in self.menuArray) {
        if ([[dic objectForKey:@"NAME"] isEqualToString:@"质量检查"]) {
            DIC = dic;
        }
        if ([[dic objectForKey:@"NAME"] isEqualToString:@"满意度调查"] ) {
            manyidu = dic;
        }
        if ([[dic objectForKey:@"NAME"] isEqualToString:@"操作过程考核"]) {
            kaohe = dic;
        }
        if ([[dic objectForKey:@"NAME"] isEqualToString:@"夜查房"]) {
            yechafang = dic;
        }
    }
    NSString *string=  [DIC objectForKey:@"PARAM"];
    NSDictionary *QC = [super getMenuParam:string];
    NSString *kaoheString=  [kaohe objectForKey:@"PARAM"];
    NSDictionary *kaohedic = [super getMenuParam:kaoheString];

    NSString *Night=  [yechafang objectForKey:@"PARAM"];
    NSDictionary *NightDic = [super getMenuParam:Night];
    

    if([title isEqualToString:@"质量检查"]){
        HSeeRecordViewController *HSeeVC = [[HSeeRecordViewController alloc]initWithLevel_ID:[QC objectForKey:@"LEVEL_ID"] param:QC isHnight:0 menu_id:[[DIC objectForKey:@"ID"]integerValue]];
        HSeeVC.title = @"检查记录";
        [self.navigationController pushViewController:HSeeVC animated:YES];
    }
    else if([title isEqualToString:@"满意度调查"]){
        HNurseAssessRecordViewController *HNurseVC = [[HNurseAssessRecordViewController alloc]initWithMenuParam:nil];
        [self.navigationController pushViewController:HNurseVC animated:YES];
        HNurseVC.title = @"历史记录";
        HNurseVC.type = @"manyidu";

    }
    else if ([title isEqualToString:@"操作过程考核"]){
        HNurseAssessRecordViewController *vc = [[HNurseAssessRecordViewController alloc]initWithMenuParam:kaohedic];
        vc.title = @"历史记录";
        vc.type = @"guochengkaohe";
        [self.navigationController pushViewController:vc animated:YES];

    }
    else if ([title isEqualToString:@"夜查房"])
    {
        HSeeRecordViewController *HSeeVC = [[HSeeRecordViewController alloc]initWithLevel_ID:[NightDic objectForKey:@"LEVEL_ID"] param:NightDic isHnight:1 menu_id:[[DIC objectForKey:@"ID"]integerValue]];
        HSeeVC.title = @"检查记录";
        [self.navigationController pushViewController:HSeeVC animated:YES];

    }
    
}

@end
